cps: experimental support for for-loops#84
Draft
alaviss wants to merge 1 commit intonim-works:masterfrom
Draft
Conversation
disruptek
requested changes
May 3, 2021
cps.nim
Outdated
| n[1] = getTypeInst n[2] | ||
| else: | ||
| # get the type from the symbol as the last resort. | ||
| # walkaround for #48. |
|
|
||
| macro cps*(T: typed, n: typed): untyped = | ||
| macro cps2(T: typed, n: typed): untyped = | ||
| # I hate doing stuff inside macros, call the proc to do the work |
Contributor
There was a problem hiding this comment.
Suggested change
| # I hate doing stuff inside macros, call the proc to do the work | |
| ## We used `getImplTransformed` to make a pre-pass whatfer transforming `for` and `defer` | |
| ## into the input to this macro, where we perform the meat of the CPS transform. |
Contributor
There was a problem hiding this comment.
I think we could use a for loop macro to remove part of the getImplTransformed dependency, I still need to think about the defer one.
Not a blocker
Comment on lines
875
to
949
| when defined(nimdoc): | ||
| result = n | ||
| else: | ||
| result = cpsXfrm(T, n) |
Contributor
There was a problem hiding this comment.
This when should move into cps().
| else: | ||
| result = cpsXfrm(T, n) | ||
|
|
||
| macro cps*(T: typed, n: typed): untyped = |
Contributor
There was a problem hiding this comment.
Suggested change
| macro cps*(T: typed, n: typed): untyped = | |
| macro cps*(T: typed, n: typed): untyped = | |
| ## Rewrite procedure `n` in Continuation-Passing Style, extending type `T` to store any transient locals. |
saem
approved these changes
May 4, 2021
Contributor
saem
left a comment
There was a problem hiding this comment.
Noted the for loop macro idea for posterity. @disruptek already highlighted the doc bits, lgtm.
For-loops are inlined using block statements, which messes with their control flow due to nim-works#76. Breaks a test in tzevv due to defer being rewritten into try-finally, which doesn't work. Co-authored-by: Andy Davidoff <github@andy.disruptek.com>
Contributor
Author
|
Rebased, compiler issues that I found:
case true
of true:
echo "true"
of false:
echo "failed"transformed to: case true
of true:
echo "true"
of false:
echo "failed"
else:
nilAnd this stuff don't pass sem, obviously.
a & b & ctransformed to And it also doesn't pass sem because a I'd say we should perform this transform ourselves. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
For-loops are inlined using block statements, which messes with their
control flow due to #76.
Breaks "for loop with continue, break" test. On the flip side,
splitting now functions on them.
Also breaks a test in tzevv due to defer being rewritten into
try-finally, which doesn't work due to #80.